package clientApp;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import clientApp.utils.RPG_Workstation_Container;
import game.units.Attribute;
import game.units.Monster;
import game.enums.Alignment;
import game.enums.Size;
import game.mechanics.Item;
import game.referenceValues.*;

/**
 *
 * @author Gabriel
 */
@SuppressWarnings("serial")
public class MonsterBuilder extends javax.swing.JPanel {

	
	RPG_Workstation_Container container;
	RPG_Workstation frame;
	private Monster monster;
	
	String[] aligns = new String[9];
	String[] sizes = new String[4];
	String[] itens = new String[1];
	String[] races = new String[1];
	Alignment[] alignEnum = Alignment.values();
	Size[] sizeEnum = Size.values();
	ArrayList<String> raceList = new ArrayList<String>();
	ArrayList<Item> itemList = new ArrayList<Item>();
	ArrayList<Item> loot = new ArrayList<Item>();
	ArrayList<String> powers = new ArrayList<String>();
	
    /** Creates new form CharacterBuilder1 */
    public MonsterBuilder(RPG_Workstation frame, RPG_Workstation_Container rpg_Workstation_Container, Monster monster) {
    	this.frame = frame;
    	this.monster = monster;
    	container = rpg_Workstation_Container;
    	initComponents();
        initObjects();
   
    
	}

	private void initObjects()
    {		
		for (int i = 0; i < alignEnum.length; i++ ) 	
		{
			aligns[i] = alignEnum[i].name();
		}
		for (int i = 0; i < sizeEnum.length; i++ ) 	
		{
			sizes[i] = sizeEnum[i].name();
		}
		Race raceGetter = new Race();
		raceList = raceGetter.getMonsterRaces();
		races = new String[raceList.size()];
		Item itemGetter = new Item();
		itemList = itemGetter.getItemList();
		itens = new String[itemList.size()];
		
		for (int i = 0; i < raceList.size(); i++ ) 	
		{
			races[i] = raceList.get(i);
		}
		for (int i = 0; i < itemList.size(); i++ ) 	
		{
			itens[i] = itemList.get(i).getName();
		}
    	jCBSize.setModel(new javax.swing.DefaultComboBoxModel(sizes));

        jCBAlignment.setModel(new javax.swing.DefaultComboBoxModel(aligns));

        jCBRace.setModel(new javax.swing.DefaultComboBoxModel(races));
    	for (int i = 0; i < races.length; i++)
    	{
    		if(races[i].equals(monster.getRace()))
    		{
    			jCBRace.setSelectedIndex(i);
    		}
    	}
    	
		if(monster.getName() != null)
		{
			jTFAC.setText(""+monster.getArmorClass());
	    	jTFBaseAttack.setText(""+monster.getAttackBase());
	    	jTFChallange.setText(""+monster.getChallenge());
	    	jTFFor.setText(""+monster.getFortitude());
	    	jTFHP.setText(""+monster.getLifePoints());
	    	jTFInitiative.setText(""+monster.getInitiative());
	    	jTFMoviments.setText(""+monster.movs);
	    	jTFName.setText(monster.getName());
	    	jTFPowerName.setText("");
	    	jTFQuantity.setText("");
	    	jTFRe.setText(""+monster.getReflex());
	    	jTFWill.setText(""+monster.getWill());
	    	jTFXP.setText("");
	    	jTADesc.setText("");
	    	loot = monster.getLoot();
	    	powers = monster.getAttacks();
	    	
	    	jLPowers.setModel(new javax.swing.AbstractListModel() {
	            ArrayList<String> pow = powers;
	            public int getSize() { return pow.size(); }
	            public Object getElementAt(int i) { return pow.get(i); }
	        });
	    	
	    	jLItens.setModel(new javax.swing.AbstractListModel() {
	    		ArrayList<Item> itans = loot;
	    		public int getSize() { return itans.size(); }
	            public Object getElementAt(int i) { return itans.get(i).getName()+"   "+ itans.get(i).getQuantity(); }
	        });
	    	

		}
	}

    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jTFName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jSeparator5 = new javax.swing.JSeparator();
        jCBSize = new javax.swing.JComboBox();
        jCBAlignment = new javax.swing.JComboBox();
        jCBRace = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jTFChallange = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTFXP = new javax.swing.JTextField();
        jBReset = new javax.swing.JButton();
        jBSave = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTFHP = new javax.swing.JTextField();
        jTFInitiative = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTFAC = new javax.swing.JTextField();
        jTFFor = new javax.swing.JTextField();
        jTFRe = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTFWill = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jSeparator6 = new javax.swing.JSeparator();
        jLabel14 = new javax.swing.JLabel();
        jSeparator7 = new javax.swing.JSeparator();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTADesc = new javax.swing.JTextArea();
        jLabel16 = new javax.swing.JLabel();
        jTFPowerName = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jBAddPower = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jTFBaseAttack = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jCBItens = new javax.swing.JComboBox();
        jBAddLoot = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jTFQuantity = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jTFMoviments = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLItens = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        jLPowers = new javax.swing.JList();

        jPanel1.setBackground(new java.awt.Color(0, 0, 102));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 28));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Monster Details");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Life Points:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Alignment:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Race:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("Size:");

        jCBSize.setModel(new javax.swing.DefaultComboBoxModel(aligns));

        jCBAlignment.setModel(new javax.swing.DefaultComboBoxModel(sizes));

        jCBRace.setModel(new javax.swing.DefaultComboBoxModel(races));

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Experience Points:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Challenge:");

        jBReset.setText("Reset");
        jBReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBResetActionPerformed(evt);
            }
        });

        jBSave.setText("Save");
        jBSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSaveActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Name:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("Initiative:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Armor Class:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Fortitude:");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("Reflexes:");

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Will:");

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Loot:");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setText("Attacks and Powers:");

        jTADesc.setColumns(20);
        jTADesc.setRows(5);
        jScrollPane2.setViewportView(jTADesc);

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel16.setForeground(new java.awt.Color(255, 255, 255));
        jLabel16.setText("Name:");

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel17.setForeground(new java.awt.Color(255, 255, 255));
        jLabel17.setText("Description:");

        jBAddPower.setText("Add");
        jBAddPower.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAddPowerActionPerformed(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel18.setForeground(new java.awt.Color(255, 255, 255));
        jLabel18.setText("List:");

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel19.setForeground(new java.awt.Color(255, 255, 255));
        jLabel19.setText("Attack:");

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel20.setForeground(new java.awt.Color(255, 255, 255));
        jLabel20.setText("Item:");

        jCBItens.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jBAddLoot.setText("Add");
        jBAddLoot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAddLootActionPerformed(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel21.setForeground(new java.awt.Color(255, 255, 255));
        jLabel21.setText("List:");

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel22.setForeground(new java.awt.Color(255, 255, 255));
        jLabel22.setText("Quantity:");

        jLabel23.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel23.setForeground(new java.awt.Color(255, 255, 255));
        jLabel23.setText("Moviments:");

        
        jScrollPane1.setViewportView(jLItens);

        
        jScrollPane3.setViewportView(jLPowers);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 576, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jTFName, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jCBRace, 0, 143, Short.MAX_VALUE)))
                                .addGap(85, 85, 85))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jTFHP, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                .addGap(54, 54, 54)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel7))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTFChallange, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jCBSize, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(jTFXP)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel8))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTFInitiative, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jCBAlignment, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel23)
                                .addGap(18, 18, 18)
                                .addComponent(jTFMoviments)))
                        .addGap(15, 15, 15))
                    .addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jBReset)
                        .addGap(8, 8, 8)
                        .addComponent(jBSave, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(18, 18, 18)
                        .addComponent(jTFAC, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(jTFFor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addGap(18, 18, 18)
                        .addComponent(jTFRe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel13)
                        .addGap(18, 18, 18)
                        .addComponent(jTFWill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel19)
                        .addGap(18, 18, 18)
                        .addComponent(jTFBaseAttack, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
                            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel21)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 234, Short.MAX_VALUE)
                                .addComponent(jBAddLoot))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel20))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCBItens, 0, 252, Short.MAX_VALUE)
                                    .addComponent(jTFQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel16)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTFPowerName, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel17))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jBAddPower)))
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel15)
                            .addComponent(jScrollPane3))
                        .addGap(51, 51, 51)))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jCBAlignment, jCBRace, jCBSize, jTFChallange, jTFHP, jTFInitiative, jTFName});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBAddPower, jBReset, jBSave});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTFAC, jTFBaseAttack, jTFFor, jTFRe, jTFWill});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel3)
                    .addComponent(jCBSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jCBAlignment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jTFChallange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jTFInitiative, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBRace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTFHP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTFXP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23)
                    .addComponent(jTFMoviments, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTFAC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTFFor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jTFRe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jTFWill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(jTFBaseAttack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jTFPowerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17)
                            .addComponent(jLabel20)
                            .addComponent(jCBItens, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22)
                            .addComponent(jTFQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jBAddPower)
                            .addComponent(jLabel18)
                            .addComponent(jBAddLoot)
                            .addComponent(jLabel21)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBReset)
                    .addComponent(jBSave))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jBResetActionPerformed(java.awt.event.ActionEvent evt) {                                        
    	monster = new Monster();
    	jTFAC.setText("");
    	jTFBaseAttack.setText("");
    	jTFChallange.setText("");
    	jTFFor.setText("");
    	jTFHP.setText("");
    	jTFInitiative.setText("");
    	jTFName.setText("");
    	jTFPowerName.setText("");
    	jTFQuantity.setText("");
    	jTFRe.setText("");
    	jTFWill.setText("");
    	jTFXP.setText("");
    	jTADesc.setText("");
    	jLPowers.setModel(new javax.swing.AbstractListModel() {
            ArrayList<String> pow = new ArrayList<String>();
            public int getSize() { return pow.size(); }
            public Object getElementAt(int i) { return pow.get(i); }
        });
    	
    	jLItens.setModel(new javax.swing.AbstractListModel() {
    		ArrayList<Item> itans = new ArrayList<Item>();
    		public int getSize() { return itans.size(); }
            public Object getElementAt(int i) { return itans.get(i); }
        });
    }

    private void jBSaveActionPerformed(java.awt.event.ActionEvent evt) {      
    
    	String[] atkBonus = (jTFBaseAttack.getText()).split("/");	
    	int[] attackB = new int[atkBonus.length];
    	for (int i =0; i< atkBonus.length; i++)
    		attackB[i] = Integer.parseInt(atkBonus[i]);
    	Monster.addDNDMonster( new Monster((String)jCBRace.getSelectedItem(), Integer.parseInt(jTFChallange.getText()), loot, powers, jTFName.getText(), " ", " ", " ", " ", Size.valueOf((String)jCBSize.getSelectedItem()), Alignment.valueOf((String)jCBAlignment.getSelectedItem()), 0, Integer.parseInt(jTFXP.getText()), Integer.parseInt(jTFAC.getText()), Integer.parseInt(jTFFor.getText()), Integer.parseInt(jTFRe.getText()), Integer.parseInt(jTFWill.getText()), attackB ,new ArrayList<Attribute>(), new ArrayList<Magic>())); 
    }

    private void jBAddPowerActionPerformed(java.awt.event.ActionEvent evt) {                                           
    	if(!jTFPowerName.getText().isEmpty() && !jTADesc.getText().isEmpty())
    	{
    		String Power = jTFPowerName.getText() + " -- " + jTADesc.getText();
    		monster.getAttacks().add(Power);
    		powers.add(Power);
    		jLPowers.setModel(new javax.swing.AbstractListModel() {
	            ArrayList<String> pow = powers;
	            public int getSize() { return pow.size(); }
	            public Object getElementAt(int i) { return pow.get(i); }
	        });
    		jTFPowerName.setText("");
    		jTADesc.setText("");
        }
    	else{
    		JOptionPane.showMessageDialog(frame, "A power needs a name and a description");
		}
    }

    private void jBAddLootActionPerformed(java.awt.event.ActionEvent evt) {                                            
    	Item item = itemList.get(jCBItens.getSelectedIndex());
        try
        {
        	 item.setQuantity(Integer.parseInt(jTFQuantity.getText()));             
             monster.getLoot().add(item);
             loot.add(item);
             jLItens.setModel(new javax.swing.AbstractListModel() {
 	    		ArrayList<Item> itans = loot;
 	    		public int getSize() { return itans.size(); }
 	            public Object getElementAt(int i) { return itans.get(i).getName()+"   "+ itans.get(i).getQuantity(); }
 	        });
             jTFQuantity.setText("");
        }
        catch (Exception e) {
        	JOptionPane.showMessageDialog(frame, "A loot require a quantity to be added to the loot list");      
        }
        	
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAddLoot;
    private javax.swing.JButton jBAddPower;
    private javax.swing.JButton jBReset;
    private javax.swing.JButton jBSave;
    private javax.swing.JComboBox jCBAlignment;
    private javax.swing.JComboBox jCBItens;
    private javax.swing.JComboBox jCBRace;
    private javax.swing.JComboBox jCBSize;
    private javax.swing.JList jLItens;
    private javax.swing.JList jLPowers;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JTextArea jTADesc;
    private javax.swing.JTextField jTFAC;
    private javax.swing.JTextField jTFBaseAttack;
    private javax.swing.JTextField jTFChallange;
    private javax.swing.JTextField jTFFor;
    private javax.swing.JTextField jTFHP;
    private javax.swing.JTextField jTFInitiative;
    private javax.swing.JTextField jTFMoviments;
    private javax.swing.JTextField jTFName;
    private javax.swing.JTextField jTFPowerName;
    private javax.swing.JTextField jTFQuantity;
    private javax.swing.JTextField jTFRe;
    private javax.swing.JTextField jTFWill;
    private javax.swing.JTextField jTFXP;
    // End of variables declaration//GEN-END:variables
}
